package com.atguigu.ssyx.sys.service.impl;


import com.atguigu.ssyx.model.sys.Ware;
import com.atguigu.ssyx.sys.mapper.WareMapper;
import com.atguigu.ssyx.sys.service.WareService;
import com.atguigu.ssyx.vo.product.WareQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 仓库表 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2025-09-12
 */
@Service
public class WareServiceImpl extends ServiceImpl<WareMapper, Ware> implements WareService {

    @Override
    public IPage<Ware> selectPageWare(Page<Ware> pageparam, WareQueryVo queryVo) {
      //获取查询条件
        String city = queryVo.getCity();
        String name = queryVo.getName();
        String province = queryVo.getProvince();
        //判断条件是否为空，不为空则查询
        LambdaQueryWrapper<Ware> queryWrapper = new LambdaQueryWrapper<>();

        if (!StringUtils.isEmpty(name)) {
            queryWrapper.like(Ware::getName, name).or().like(Ware::getProvince, province).or().like(Ware::getCity, city);
        }

        Page<Ware> warePage = baseMapper.selectPage(pageparam, queryWrapper);
        //返回结果
        return warePage;
    }



    @Override
    public Ware selectWareByName(String wareName) {
        return baseMapper.selectWareByName(wareName);
    }

    @Override
    public void updateIsdeleteById(Long id) {
         baseMapper.updateIsdeleteById(id);
    }
}
